package com.yangfan.thread.thread_wangwenjun09;

import java.util.Random;

/**
 * @description:
 * @author: yangfan
 * @date: Created in 2020/2/12 0012 15:02
 * @modified By:
 */
public class ServerThread extends Thread {


    private final RequestServer server;

    private volatile boolean flag = false;

    public ServerThread(RequestServer server) {
        this.server = server;
    }


    @Override
    public void run() {


        while(!flag){

            Request request = server.getRequest();

            if(request == null){

                System.out.println("没有任务了！要进行关闭了！");

                continue;
            }

            System.out.println("服务端接收到消息:" + request.getValue());

            try {
                Thread.sleep(new Random().nextInt(1_000));
            } catch (InterruptedException e) {
                break;
            }

        }


    }


    public void closed(){
        flag = true;
        this.interrupt();
    }



}
